package com.ldzy.service.impl;

import com.ldzy.dao.UserMapper;
import com.ldzy.exception.UserException;
import com.ldzy.pojo.ResultCode;
import com.ldzy.pojo.User;
import com.ldzy.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public User login(User user) throws UserException {
        User user1=userMapper.login(user);
        if(user1!=null){
            System.out.println(user1.getName());
            String status=user1.getStatus();
            if(status.equals("0"))
                return userMapper.login(user);
            else throw new UserException(ResultCode.ERROR_USER_DISABLED);
        }
        else throw new UserException(ResultCode.ERROR_NAME_PASSWORD);
    }
}
